img=imread('cover.tif');
double_img=double(img);   %将uint8转成im2double型便于后期计算
[width,height]=size(double_img);

%motion = fspecial('motion', 60, 135);%运动长度为18，逆时针运动角度为90°
%motion_blur = imfilter(double_img, motion, 'conv', 'circular');%卷积滤波

T=1;
a=0.01;
b=0.01;
F=fft2(double_img);
H=zeros(width,height);
for u=1:width
    for v=1:height
        temp=pi*(u*a+v*b);
        H(u,v)=T*sin(temp)*exp(-temp*1i*pi)/temp;
    end
end
G=F.*H;
hp=ifft2(G);
motion_blur=real(hp);
motion_blur=motion_blur/max(motion_blur(:));

noise_mean=0;  %均值
noise_var=0.005; %方差
img_noise=imnoise(img,'gaussian',noise_mean,noise_var);
motion_noise=imnoise(motion_blur,'gaussian',noise_mean,noise_var);

figure;
subplot(2,2,1);imshow(img);title('原始图像');
subplot(2,2,2);imshow(motion_blur);title('运动模糊图像');
subplot(2,2,3);imshow(img_noise);title('添加高斯噪声的图像');
subplot(2,2,4);imshow(motion_noise);title('模糊且加噪的图像');